<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	     <title>工序信息管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/layout.css" />
  </head>
  <body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="/common/head.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：基本资料管理 &gt; 工序信息管理</div>
	<div id="REC_content">
	    <fieldset id="BasicInfo" class="mainField">
		    <legend><span class="title">工序信息管理</span></legend>
			<div class="innerCon">
			    <div class="mainSearchBox">
			      <form:form action="ws.do" method="post" enctype="multipart/form-data" modelAttribute="ws">
			       <table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
			        <tr height="35">
						<td width="80" class="title">工序编号</td>
						<td align="left"><form:input path="wsId" id="wsId"/></td>
						<td width="80" class="title">工序名称</td>
						<td align="left"><form:input path="wsName" id="wsName"/></td>
						<td width="80" class="title">工序类型</td>
						<td align="left"> 
						  <form:select path="wsType">
						    <form:option value="计件">计件</form:option>
						    <form:option value="非计件">非计件</form:option>
						  </form:select>
						</td>
					</tr>
					<tr height="35">
						<td width="80" class="title">备注</td>
						<td align="left"><form:input path="wsComment" id="wsId"/></td>
						<td width="190" colspan="4" align="left">
						  <input type="button" name="searchButton" class="newSearchButton" value="新增" onclick="create()"/> 
						  <input type="submit" name="searchButton" class="newSearchButton" value="查询" /> 
						</td>
					</tr>
				</table>
				</form:form>
			    </div>
			    <!-- begin tab -->
			    <div class="topControl clearfix">
				    <div id="JobsMgrTabCon" class="itemTabCon">
					    <ul id="JobsMgrTabs" class="itemTabs">
							<li id="dueTab" class="blur"><a href="<%=basePath%>staff.do" >员工信息管理</a></li>
							<li id="dueTab" class="focus"><a href="<%=basePath%>ws.do"  onfocus="this.blur()">工序信息管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>route.do">路由设置管理</a></li>
					    </ul>
				    </div>
			    </div>
			    
			    
			    <!-- end tab -->
				<div id="mainListCon">
				    <div id="mLC">
					    <ul>
						    <li id="result">
							    <table width="888" style="border:1px solid #eee;" cellpadding="0" cellspacing="1" >
								    <tr bgcolor="#f2f6f9">
								        <td width="10%">编号</td>
									    <td width="30%">工序名称</td>
										<td width="25%">工序类型</td>
										<td width="5%">工序说明</td>
										<td width="30%"></td>
									</tr>
									<c:forEach var="ws" items="${dataList}" varStatus="idx">
									<tr class="${idx.index%2==0?'list1':'list2'}" id="${ws.wsId}">
								     	<td>${ws.wsId}</td>
									    <td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="Name${ws.wsId}" value="${ws.wsName}" /></td>
									    <td>
									       <select id="Type${ws.wsId}">
										      <option ${ws.wsType eq "非计件"?"selected":""}>非计件</option>
										      <option ${ws.wsType eq "计件"?"selected":""}>计件</option>
										    </select>
									    </td>
										<td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="Com${ws.wsId}" value="${ws.wsComment}" />
										</td>
										<td>
										  <input name="" class="newSearchButton" type="button" class="btn" onclick="update(${ws.wsId})" value="修改" /> 
										  <input name="" class="newSearchButton" type="button" class="btn" value="删除" onclick="del(${ws.wsId})"/>
									    </td>
									</tr>
									</c:forEach>
								</table> 
							</li>
						</ul>
					</div>
				</div>
			</div>
		</fieldset>
	</div>
	<jsp:include page="/common/foot.jsp"></jsp:include>
</div>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"language="javascript"></script>
    <script src='<%=basePath%>dwr/interface/wsService.js'></script>
    <script src="<%=basePath%>dwr/engine.js"></script>
    <script src="<%=basePath%>dwr/util.js"></script>
           <script type="text/javascript" language="javascript">
             function del(wsid){
               if(confirm("确定要删除编号为:"+wsid+"的工序吗?")){
                wsService.removeWs(wsid,function(i){
                  if(i>0){
                   $("#"+wsid).remove();
                   alert("删除成功!");
                  }else{
                   alert("删除失败!");
                  }
                });
               }else return;
             }
             
             function selectList(){
               var id = $.trim($("#wsId").val());
               var name = $.trim($("#wsName").val());
               var wsType = $.trim($("#wsType").val());
               $("#loading").removeAttr("style");
               wsService.queryWsListByClause({wsId:id,wsName:name,wsType:wsType},callbackFunction);
             }
             
             var callbackFunction = function(data){
              
              $("#result").empty();
              var appendData = "<table border='1' width='100%' id='resultTable'>";
               appendData+="<tr>";
               appendData+="<th>编号</th>";
               appendData+="<th>工序名称</th>";
               appendData+="<th>工序类型</th>";
               appendData+="<th>工序说明</th>";
               appendData+="<th>操作</th>";
               appendData+="</tr>";
             for(var property in data){ 
               appendData+="<tr id='"+data[property].wsId+"'>";
               appendData+="<td>"+data[property].wsId+"</td>";
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Name"+data[property].wsId+"' value='"+data[property].wsName+"' /></td>";
               if(data[property].wsType=="计件")
               appendData+="<td><select id='Type"+data[property].wsId+"' onchange=this.style.backgroundColor='#E5F0FF';><option selected>计件</option><option>非计件</option></select></td>";
               else
               appendData+="<td><select id='Type"+data[property].wsId+"' onchange=this.style.backgroundColor='#E5F0FF';><option>计件</option><option selected>非计件</option></select></td>";
               
               appendData+="<td><input type='text' onchange=this.style.backgroundColor='#E5F0FF'; id='Com"+data[property].wsId+"' value='"+data[property].wsComment+"' /></td>";
               appendData+="<td><input type='button' value='删除' onclick='del("+data[property].wsId+")'/>";
               appendData+="<input type='button' value='修改' onclick='update("+data[property].wsId+")'/></td>";
               appendData+="</tr>";
             }
             appendData+="</table>";
             $("#result").append(appendData);    
             };
             
             function create(){
               //var id = $.trim($("#wsId").val());
               var name = $.trim($("#wsName").val());
               var wsType = $.trim($("#wsType").val());
               var wsCom = $.trim($("#wsCom").val());
               
               if(wsType==""||name==""){
                 alert("工序类型或工序名称不能为空!");
                 return;
               }else{
                 wsService.createWs({wsName:name,wsType:wsType,wsComment:wsCom},function(i){
                   if(i==1){
                     alert("新增成功!");
                     $("#wsType").attr("value",'');
                     $("#wsName").attr("value",'');
                     $("#wsCom").attr("value",'');
                     window.location.reload();
                   }else if(i==0){
                     alert("新增失败!已存在名称为:"+name+"的工序!");
                   }else{
                     alert("新增失败!");
                   }
                 });
               }
             }
             
             function update(Id){
               var name = $.trim($("#Name"+Id).val());
               var wsType = $.trim($("#Type"+Id).val());
               var wsCom = $.trim($("#Com"+Id).val());
              if(name==""||wsType==""){
                 alert("工序名称或工序类型不能修改为空!");
                 return;
               }else{
                 wsService.updateWs({wsId:Id,wsName:name,wsType:wsType,wsComment:wsCom},function(i){
                   if(i==1){
                     alert("修改成功!");
                     $("#Name"+Id).removeAttr("style");
                     $("#Type"+Id).removeAttr("style");
                     $("#Com"+Id).removeAttr("style");
                     window.location.reload();
                   }else{
                     alert("修改失败!");
                   }
                 });
               }
             }
           </script>
  </body>
</html>
